package com.jqsoft.launcher.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetBroadcastReceiver extends BroadcastReceiver {
	private NetContentListener netContentListener;

	@Override
	public void onReceive(Context context, Intent intent) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo mobNetInfo = connectivityManager
				.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		NetworkInfo wifiNetInfo = connectivityManager
				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

		if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {
			// 改变背景或者 处理网络的全局变量
			netContentListener.netContent(false);
		} else {
			// 改变背景或者 处理网络的全局变量
			netContentListener.netContent(true);
		}

	}

	public NetBroadcastReceiver() {
	}

	public void setNetContentListener(NetContentListener netContentListener) {
		this.netContentListener = netContentListener;
	}

	public interface NetContentListener {
		void netContent(boolean isConnected);
	}

}
